#include "../include/client.h"

int recvCmd(int sockfd, char *buf, int *flag){
    train_t train;
    bzero(&train,sizeof(train));
    int ret = recv(sockfd,&train.flag,sizeof(train.flag),0);
    if(ret == 0){
        return -1;
    }
    recv(sockfd,&train.length,sizeof(train.length),0);
    recv(sockfd,train.data,train.length,MSG_DONTWAIT);
    *flag = train.flag;
    memcpy(buf,train.data,sizeof(train.data));
    //printf("%ld\n",strlen(buf));
    //if(strlen(buf)!=0){
    //    buf[strlen(buf)-1] = '\0';
    //}
    return 0;
}
